package com.multicampus.sample.video;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class TransCodeRuntime extends Thread {
	InputStream io;

	public TransCodeRuntime(InputStream io) {
		this.io = io;
	}

	public static void main(String[] args) throws Exception {
		Runtime runtime = Runtime.getRuntime();
		Process process = runtime.exec("ffmpeg -y -i sample_iPod.m4v -b 64k -ar 22050 -f swf sample_iPod.swf", null, new File(
				"C:/down/movie_source/sample"));
		
		TransCodeRuntime trans1 = new TransCodeRuntime(process.getErrorStream());
		TransCodeRuntime trans2 = new TransCodeRuntime(process.getInputStream());
		
		trans1.start();
		trans2.start();
		
		int exitVal = process.waitFor();
		System.out.println("ExitValue: " + exitVal);
	}

	@Override
	public void run() {
		try {
			InputStreamReader isr = new InputStreamReader(io);
			BufferedReader br = new BufferedReader(isr);

			String line = null;
			while ((line = br.readLine()) != null)
				System.out.println(">" + line);
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
}
